﻿using Assimp;
using Assimp.Configs;
using System;
using System.IO;
using System.Reflection;


namespace OpenTKBasics.AssimpNet
{
    class Program
    { 
        static void Demo1(string fileName)
        { 
            //Filepath to our model String fileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Seymour.dae");

            //Create a new importer
            AssimpContext importer = new AssimpContext();

            //This is how we add a configuration (each config is its own class)
            NormalSmoothingAngleConfig config = new NormalSmoothingAngleConfig(66.0f);
            importer.SetConfig(config);

            //This is how we add a logging callback 
            LogStream logstream = new LogStream(delegate (String msg, String userData) {
                Console.WriteLine(msg);
            });
            logstream.Attach();

            //Import the model. All configs are set. The model
            //is imported, loaded into managed memory. Then the unmanaged memory is released, and everything is reset.
            Scene scene = importer.ImportFile(fileName, PostProcessPreset.TargetRealTimeMaximumQuality);
            if ( scene==null || scene.SceneFlags==SceneFlags.Incomplete || scene.RootNode == null )
            { Console.WriteLine("ERROR::ASSIMP"); }

            //TODO: Load the model data into your own structures

            //End of example
            importer.Dispose();
        }

        static void Demo2(string[] args)
        {
            //Filepath to our model
            String fileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Seymour.dae");

            //Create a new importer
             
            //AssimpImporter importer = new AssimpImporter();
            AssimpContext importer = new AssimpContext();  

            //This is how we add a configuration (each config is its own class)
            NormalSmoothingAngleConfig config = new NormalSmoothingAngleConfig(66.0f);    
            importer.SetConfig(config);
            //MeshTriangleLimitConfig limitConfig = new MeshTriangleLimitConfig(9999999);
            //TransformUVConfig uvConfig = new TransformUVConfig();

            //This is how we add a logging callback 
            LogStream logstream = new LogStream(delegate (String msg, String userData) {
                Console.WriteLine(msg);
            });

            logstream.Attach();
            //importer.AttachLogStream(logstream);

            //Import the model - this is considered a single atomic call. All configs are set, all logstreams attached. The model
            //is imported, loaded into managed memory. Then the unmanaged memory is released, and everything is reset.
            Scene scene = importer.ImportFile(fileName,
                PostProcessPreset.TargetRealTimeMaximumQuality  
                | PostProcessSteps.Triangulate 
                | PostProcessSteps.FlipUVs 
                | PostProcessSteps.CalculateTangentSpace
                );

            //Load the model data into your own structures

            //End of example
            importer.Dispose();
        }
    }
}